<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <ul>
      <li v-for="cate in cates" :key="cate.id">
        <h4>
          {{ cate.name }}
        </h4>
        <img :src="cate.icon" alt="">
      </li>
    </ul>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>
  <script>
    // https://api.it120.cc/conner
    const vm = new Vue({
      el: '#app',
      data: {
        cates: [] // 1在data中定义初始化
      },
      methods: {
        fetchCates () {
          // 2封装请求函数
          /* axios.get('https://api.it120.cc/conner/shop/goods/category/all?page=1&pageSize=5').then(res=> {
            if(res.data.code === 0) {
              this.cates = res.data.data
            }
          }) */
          axios.get('https://api.it120.cc/conner/shop/goods/category/all', {
            // config params属性代表get请求的参数
            params: {
              page: 1,
              pageSize: 2
            }
          }).then(res => {
            if(res.data.code === 0) {
              this.cates = res.data.data
            }
          })
        }
      },
      created(){
        // 3在初始化钩子函数中调用
        this.fetchCates();
      }
    })
  </script>
</body>
</html>